package com.wyvoid.forum.dao.hibernate;

import com.wyvoid.core.persistent.hibernate.HibernateDAO;
import com.wyvoid.core.persistent.hibernate.HibernatePage;
import com.wyvoid.core.persistent.Pagination;
import com.wyvoid.forum.dao.IUserProfileDAO;
import com.wyvoid.forum.domain.UserProfile;

/**
 * <p>51void.com</p>
 * User:cjp
 * Date: 2007-5-13
 * Time: 12:12:11
 */
public class UserProfileDAO extends HibernateDAO<UserProfile> implements IUserProfileDAO {
    public UserProfile getUserProfile(long userId) {
        return doQueryUnique("from UserProfile as up where up.user.id=?", userId);
    }

    /**
     * User：qijing
     * 获得所有的会员信息 并按照注册的时间来排序
     *
     * @param pagination
     * @return 会员信息
     */
    public HibernatePage getAllUser(Pagination pagination) {
        String hql = "from UserProfile up order by up.user.registerTime desc";
        return doQuery(hql, true, pagination);
    }

    /**
     * user:qijing
     * 对USER表进行查询都放到这边
     *
     * @return 对会员表查询的结果
     */
    public HibernatePage getSearchUser(String strUserKey, Pagination pagination) {
        String hql = "from UserProfile up order by up.user." + strUserKey + " desc";
        return doQuery(hql, true, pagination);
    }

    /*
    * 根据给出的关键字段查询会员用户
    */
    public HibernatePage getSearchUserName(String strUserName, Pagination pagination) {
        String hql = "from UserProfile up where up.user.username like ?";
        return doQuery(hql, true, pagination,"%"+strUserName+"%");
    }

    public UserProfile getUserProfileByUserName(String userName) {
        return doQueryUnique("from userProfile up where up.user.username=?", userName);
    }
}
